package ro.gateway.aida.sectors;

import ro.gateway.aida.obj.AIDASector;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: ro-gateway</p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: SectorWrapper.java,v 1.1 2004/10/24 23:37:09 mihaipostelnicu Exp $
 */
public class SectorWrapper
{
      AIDASector sector;
      String lang;

      public SectorWrapper( AIDASector sector, String lang )
      {
            this.sector = sector;
            this.lang = lang;
      }

      public AIDASector getSector()
      {
            return sector;
      }

      public String getTitle()
      {
            String result = null;
            if ( sector != null )
            {
                  result = this.sector.getTitle( lang );
                  if ( result.length() > 40 )
                  {
                        result.substring( 0, 40 );
                  }
            }

            return result;
      }

      public String getParentTitle()
      {
            if ( sector == null ) return null;
            if ( sector.getParent() == null ) return null;

            String result = sector.getParent().getTitle( lang );
            if ( result.length() > 40 )
            {
                  result = result.substring( 0, 40 );
            }
            return result;
      }

      public String getGrandParentTitle()
      {
            if ( sector == null ) return null;
            if ( sector.getParent() == null ) return null;
            if ( sector.getParent().getParent() == null ) return null;

            String result = sector.getParent().getParent().getTitle( lang );
            if ( result.length() > 40 )
            {
                  result = result.substring( 0, 40 );
            }
            return result;
      }

      public int getRo_aida_code()
      {
            if ( sector == null ) return -1;
            return sector.getRo_aida_code();
      }

      public static SectorWrapper[] wrapp( AIDASector[] sectors, String lang )
      {
            if ( sectors == null ) return null;

            SectorWrapper[] result = new SectorWrapper[ sectors.length ];
            for ( int i = 0; i < result.length; i++ )
            {
                  result[ i ] = new SectorWrapper( sectors[ i ], lang );

            }

            return result;
      }

      public static AIDASector[] unwrapp( SectorWrapper[] sectors )
      {
            if ( sectors == null ) return null;

            AIDASector[] result = new AIDASector[ sectors.length ];
            for ( int i = 0; i < result.length; i++ )
            {
                  result[ i ] = sectors[ i ].sector;

            }

            return result;
      }
}
